from typing import overload
from numpy import array
from pandas import Series, DataFrame, Index


class _BaseSelector(object):
    """
    Base class of feature selector.
    Parameters:
        x: Dataframe, (timestamp, n_features)
        y: Series, (timestamp,)
        n_selected_features: int, number of selected features
    """

    x: DataFrame
    y: Series
    n_selected_features: int = 1000

    def __init__(self, x: DataFrame, y: Series, n_selected_features: int = 1000) -> None:
        self.x = x
        self.y = y
        self.n_selected_features = n_selected_features if self.x.shape[1] > n_selected_features else self.x.shape[1]

    def select_features(self, *args, **kwargs):
        raise NotImplementedError('Implement this method in the subclass.')

    @overload
    def sort_features(self, scores: Series) -> Index:
        pass

    def sort_features(self, scores: array) -> Index:
        """
        Parameters:
            scores: array or Series, scores of feature selection
        Return:
            Index, names of sorted selected features
        """
        selected_features = Series(scores, index=self.x.columns)
        selected_features.sort_values(ascending=False, inplace=True)
        return selected_features.index[: self.n_selected_features]
